<%--
  Created by IntelliJ IDEA.
  User: 孙伟业
  Date: 2020/6/3
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"  %>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>dongtai</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="../../css/bootstrap.min.css" rel="stylesheet">
    <link href="../../css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="../../css/site.css" rel="stylesheet">
    <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<div class="container">


        <div class="span9">


            <table class="table table-bordered" id="post">

            </table>



            <script src="../../jquery/jquery-3.4.1.js"></script>

            <script>

                function show() {
                    $.ajax({
                        url:'/forum/usercenter/selectAll',
                        dataType:"json",
                        type:"get",
                        success:function (data) {
                            console.log(data)
                            showInfo(data)
                        }
                    })
                }

                function showInfo(jsonObj){
                    console.log(jsonObj)
                    var html = '<tr><th>用户编号</th><th>用户姓名</th><th>用户性别</th><th>用户生日</th><th>地区</th><th>地区</th></tr>'
                    for(var i = 0; i < jsonObj.length; i ++){
                        html = html + "<tr><td>"
                        html = html + jsonObj[i].userId
                        html = html + "</td><td>"
                        html = html + jsonObj[i].userName
                        html = html + "</td><td>"
                        html = html + jsonObj[i].userSex
                        html = html + "</td><td>"
                        html = html + jsonObj[i].userBirthday
                        html = html + "</td><td>"
                        html = html + jsonObj[i].userArea
                        html = html + "</td><td>"
                        // html = html + '<a onclick=\"deleteBy(" + jsonObj[i].userId + ")\" href="javascript:;" >删除</a>'
                        html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-danger\" title=\"删除\" onclick=\"deleteBy(" + jsonObj[i].userId + ")\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>"


                        html = html + "</td></tr>"
                    }

                    var table = document.getElementById("post");
                    // innerHTML会解析后面字符串中的html标签
                    table.innerHTML = html
                }

                show()


                function deleteBy(info) {
                    alert(info)

                    var parmeter = "userId=" + info

                    $.ajax({
                        url:"/forum/usercenter/deleteUser",
                        data: parmeter,
                        type: "post",
                        success:function(data){
                            if (data == "success"){
                                alert("删除成功")
                                location.replace(location.href);
                            } else {
                                alert("删除失败")
                            }
                        }
                    })

                }

            </script>
        </div>
    </div>
</div>

</body>
</html>
